Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mem limit #286

Closed
wants to merge 1 commit into from
Closed

Fix mem limit #286

wants to merge 1 commit into from

Conversation

seansan
Copy link
Contributor

@seansan seansan commented Jun 13, 2017

@sreichel
Copy link
Contributor

Original Post:

Steps to reproduce:

in app/code/core/Mage/Catalog/Model/Product/Image.php, on line 186,

if (!isSet($memoryLimit[0])) {

incorrectly refers to $memoryLimit as an array with index [0]. The variable is not an array, so the if statement always evaluates to true and the memoryLimit is ALWAYS interpreted to be 128M regardless of the setting in php.ini

if (!isSet($memoryLimit[0])) {
    $memoryLimit = "128M";
}

Corrected code below:

if (!isSet($memoryLimit)) {
    $memoryLimit = "128M";
}

Expected Result:

Memory limit should be pulled from php.ini from ini

Actual Result:

always evaluates to true and uses 128M hardcoded setting from code.


@seansan This is not a bug ... it's absolutly corret! $memoryLimit[0] gives you the first char of $memoryLimit string. If ini_get('memory_limit') returns an empty string limit is set to 128M.

With this PR !isSet($memoryLimit) would be false because it is set - it's just an empty string - and return value would be string '' (length=0)

See: http://php.net/manual/en/function.isset.php (Example #1)

So please check code before PR :)

@@ -183,7 +183,7 @@ protected function _getMemoryLimit()
{
$memoryLimit = trim(strtoupper(ini_get('memory_limit')));

if (!isSet($memoryLimit[0])){
if (!isSet($memoryLimit)){
Copy link
Contributor

@LeeSaferite LeeSaferite Jun 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is doing what you think it's doing.
$memoryLimit = trim(strtoupper(ini_get('memory_limit'))); will always set the variable. As far as I can tell, empty($memoryLimit) is the proper check in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe keep it the way it is?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me ... I see no need to change this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of isset() on an empty string is true. This should be if (empty($memoryLimit)) {.

php > $a = '';
php > var_dump(isset($a));
php shell code:1:
bool(true)

@seansan
Copy link
Contributor Author

seansan commented Jun 13, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants